home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 344 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Subject: Re: RND
  2. References: <709.6578T1027T1962@login.eunet.no>
  3. X-Newsreader: TIN [version 1.2 PL2]
  4. Path: imada.ou.dk!breese
  5. From: breese@imada.ou.dk (Bjorn Reese)
  6. Message-ID: <1996Jan6.190221.7989@imada.ou.dk>
  7. Sender: news@imada.ou.dk
  8. Nntp-Posting-Host: wagner.imada.ou.dk
  9. Organization: Dept. of Math. & Computer Science, Odense University, Denmark
  10. Date: Sat, 6 Jan 1996 19:02:21 GMT
  11. Newsgroups: comp.sys.amiga.programmer
  12.  
  13. Patrick Hanevold (patrick.hanevold@login.eunet.no) wrote:
  14.  
  15. > RND     MACRO
  16. >         move.w  (a0),\1
  17. >         move.w  2(a0,\1.l*2),\1
  18. >         move.w  \1,(a0)
  19. >         ENDM
  20.  
  21. This is very likely to result in a cycle, hence decreasing the
  22. random sequence drastically.
  23.  
  24. A way to get around this problem is to use an additive pseudo-
  25. random generator (warning: off the top of my head)
  26.  
  27. Init:
  28.   - Keep an array of N elements. N is 2^n. Each element is seeded
  29.     by another - more CPU intensive - random generator.
  30.   - Use two indexes, i1 = 0 and i2 = N - 3
  31.  
  32. Random:
  33.   - Update the indexes (i = (i - 1) AND (N-1))
  34.   - rnd = array[i1] + array[i2]
  35.   - array[i2] = rnd
  36.   - Return rnd
  37.  
  38. --
  39. Bjorn Reese                      Email: breese@imada.ou.dk
  40. Odense University, Denmark       URL:   http://www.imada.ou.dk/~breese
  41.  
  42. "It's getting late in the game to show any pride or shame" - Marillion
  43.